<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>RF22: RF22Mesh.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">RF22
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">RF22Mesh.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// RF22Mesh.h</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Author: Mike McCauley (mikem@open.com.au)</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2011 Mike McCauley</span>
<a name="l00005"></a>00005 <span class="comment">// $Id: RF22Mesh.h,v 1.3 2011/02/15 04:51:59 mikem Exp $</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="preprocessor">#ifndef RF22Mesh_h</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span><span class="preprocessor">#define RF22Mesh_h</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;RF22Router.h&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">// Types of RF22Mesh message, used to set msgType in the RF22MeshHeader</span>
<a name="l00013"></a>00013 <span class="preprocessor">#define RF22_MESH_MESSAGE_TYPE_APPLICATION                    0</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST        1</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor">#define RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE       2</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#define RF22_MESH_MESSAGE_TYPE_ROUTE_FAILURE                  3</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment">/////////////////////////////////////////////////////////////////////</span>
<a name="l00019"></a>00019 <span class="comment">/// \class RF22Mesh RF22Mesh.h &lt;RF22Mesh.h&gt;</span>
<a name="l00020"></a>00020 <span class="comment">/// \brief RF22 subclass for sending addressed, optionally acknowledged datagrams</span>
<a name="l00021"></a>00021 <span class="comment">/// multi-hop routed across a network, with automatic route discovery</span>
<a name="l00022"></a>00022 <span class="comment">///</span>
<a name="l00023"></a>00023 <span class="comment">/// Extends RF22Router to add automatic route discovery within a mesh of adjacent nodes, </span>
<a name="l00024"></a>00024 <span class="comment">/// and route signalling.</span>
<a name="l00025"></a>00025 <span class="comment">///</span>
<a name="l00026"></a>00026 <span class="comment">/// Unlike RF22Router, RF22Mesh can be used in networks where the network topology is fluid, or unknown, </span>
<a name="l00027"></a>00027 <span class="comment">/// or if nodes can mode around or go in or out of service. When a node wants to send a </span>
<a name="l00028"></a>00028 <span class="comment">/// message to another node, it will automcatically discover a route to the destaintion node and use it. </span>
<a name="l00029"></a>00029 <span class="comment">/// If the route becomes unavailable, a new route will be discovered.</span>
<a name="l00030"></a>00030 <span class="comment">///</span>
<a name="l00031"></a>00031 <span class="comment">/// \par Route Discovery</span>
<a name="l00032"></a>00032 <span class="comment">///</span>
<a name="l00033"></a>00033 <span class="comment">/// When a RF22Mesh mesh node is initialised, it doe not know any routes to any other nodes </span>
<a name="l00034"></a>00034 <span class="comment">/// (see RF22Router for details on route and the routing table).</span>
<a name="l00035"></a>00035 <span class="comment">/// When you attempt to send a message with sendtoWait, will first check to see if there is a route to the </span>
<a name="l00036"></a>00036 <span class="comment">/// destinastion node in the routing tabl;e. If not, it wil initialite &#39;Route Discovery&#39;.</span>
<a name="l00037"></a>00037 <span class="comment">/// When a node needs to discover a route to another node, it broadcasts MeshRouteDiscoveryMessage </span>
<a name="l00038"></a>00038 <span class="comment">/// with a message type of RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST. </span>
<a name="l00039"></a>00039 <span class="comment">/// Any node that receives such a request checks to see if it is a request for a route to itself</span>
<a name="l00040"></a>00040 <span class="comment">/// (in which case it makes a unicast reply to the originating node with a </span>
<a name="l00041"></a>00041 <span class="comment">/// MeshRouteDiscoveryMessage </span>
<a name="l00042"></a>00042 <span class="comment">/// with a message type of RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE) </span>
<a name="l00043"></a>00043 <span class="comment">/// otherwise it rebroadcasts the request, after adding itself to the list of nodes visited so </span>
<a name="l00044"></a>00044 <span class="comment">/// far by the request.</span>
<a name="l00045"></a>00045 <span class="comment">///</span>
<a name="l00046"></a>00046 <span class="comment">/// If a node receives a RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST that already has itself </span>
<a name="l00047"></a>00047 <span class="comment">/// listed in the visited nodes, it knows it has already seen and rebroadcast this request, </span>
<a name="l00048"></a>00048 <span class="comment">/// and threfore ignores it. This prevents broadcast storms.</span>
<a name="l00049"></a>00049 <span class="comment">/// When a node receives a RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST it can use the list of </span>
<a name="l00050"></a>00050 <span class="comment">/// nodes aready visited to deduce routes back towards the originating (requesting node). </span>
<a name="l00051"></a>00051 <span class="comment">/// This also means that when the destination node of the request is reached, it (and all </span>
<a name="l00052"></a>00052 <span class="comment">/// the previous nodes the request visited) will have a route back to the originating node. </span>
<a name="l00053"></a>00053 <span class="comment">/// This means the unicast RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE </span>
<a name="l00054"></a>00054 <span class="comment">/// reply will be routed successfully back to the original route requester.</span>
<a name="l00055"></a>00055 <span class="comment">///</span>
<a name="l00056"></a>00056 <span class="comment">/// The RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE sent back by the destination node contains </span>
<a name="l00057"></a>00057 <span class="comment">/// the full list of nodes that were visited on the way to the destination.</span>
<a name="l00058"></a>00058 <span class="comment">/// Therefore, intermediate nodes that route the reply back towards the originating node can use the </span>
<a name="l00059"></a>00059 <span class="comment">/// node list in the reply to deduce routes to all the nodes between it and the destination node.</span>
<a name="l00060"></a>00060 <span class="comment">///</span>
<a name="l00061"></a>00061 <span class="comment">/// Therefore, RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST and </span>
<a name="l00062"></a>00062 <span class="comment">/// RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE together ensure the original requester and all </span>
<a name="l00063"></a>00063 <span class="comment">/// the intermediate nodes know how to route to the source and destination nodes and every node along the path.</span>
<a name="l00064"></a>00064 <span class="comment">///</span>
<a name="l00065"></a>00065 <span class="comment">/// Note that there is a race condition here that can effect routing on multipath routes. For example, </span>
<a name="l00066"></a>00066 <span class="comment">/// if the route to the destination can traverse several paths, last reply from the destination </span>
<a name="l00067"></a>00067 <span class="comment">/// will be the one used.</span>
<a name="l00068"></a>00068 <span class="comment">///</span>
<a name="l00069"></a>00069 <span class="comment">/// \par Route Failure</span>
<a name="l00070"></a>00070 <span class="comment">///</span>
<a name="l00071"></a>00071 <span class="comment">/// RF22Router (and therefore RF22Mesh) use reliable hop-to-hop delivery of messages using </span>
<a name="l00072"></a>00072 <span class="comment">/// hop-to-hop acknowledgements, but not end-to-end acknowledgements. When sendtoWait() returns, </span>
<a name="l00073"></a>00073 <span class="comment">/// you know that the message has been delivered to the next hop, but not if it is (or even if it can be) </span>
<a name="l00074"></a>00074 <span class="comment">/// delivered to the destination node. If during the course of hop-to-hop routing of a message, </span>
<a name="l00075"></a>00075 <span class="comment">/// one of the intermediate RF22Mesh nodes finds it cannot deliver to the next hop </span>
<a name="l00076"></a>00076 <span class="comment">/// (say due to a lost route or no acknwledgement from the next hop), it replies to the </span>
<a name="l00077"></a>00077 <span class="comment">/// originator with a unicast MeshRouteFailureMessage RF22_MESH_MESSAGE_TYPE_ROUTE_FAILURE message. </span>
<a name="l00078"></a>00078 <span class="comment">/// Intermediate nodes (on the way beack to the originator)</span>
<a name="l00079"></a>00079 <span class="comment">/// and the originating node use this message to delete the route to the destination </span>
<a name="l00080"></a>00080 <span class="comment">/// node of the original message. This means that if a route to a destination becomes unusable </span>
<a name="l00081"></a>00081 <span class="comment">/// (either because an intermediate node is off the air, or has moved out of range) a new route </span>
<a name="l00082"></a>00082 <span class="comment">/// will be established the next time a message is to be sent.</span>
<a name="l00083"></a>00083 <span class="comment">///</span>
<a name="l00084"></a>00084 <span class="comment">/// \par Message Format</span>
<a name="l00085"></a>00085 <span class="comment">///</span>
<a name="l00086"></a>00086 <span class="comment">/// RF22Mesh uses a number of message formats layered on top of RF22Router:</span>
<a name="l00087"></a>00087 <span class="comment">/// - MeshApplicationMessage (message type RF22_MESH_MESSAGE_TYPE_APPLICATION). </span>
<a name="l00088"></a>00088 <span class="comment">///   Carries an application layer message for the caller of RF22Mesh</span>
<a name="l00089"></a>00089 <span class="comment">/// - MeshRouteDiscoveryMessage (message types RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST </span>
<a name="l00090"></a>00090 <span class="comment">///   and RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE). Carries Route Discovery messages </span>
<a name="l00091"></a>00091 <span class="comment">///   (broadcast) and replies (unicast).</span>
<a name="l00092"></a>00092 <span class="comment">/// - MeshRouteFailureMessage (message type RF22_MESH_MESSAGE_TYPE_ROUTE_FAILURE) Informs nodes of </span>
<a name="l00093"></a>00093 <span class="comment">///   route failures.</span>
<a name="l00094"></a>00094 <span class="comment">///</span>
<a name="l00095"></a>00095 <span class="comment">/// Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers </span>
<a name="l00096"></a>00096 <span class="comment">/// (see http://www.hoperf.com)</span>
<a name="l00097"></a><a class="code" href="classRF22Mesh.html">00097</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="classRF22Mesh.html" title="RF22 subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a netw...">RF22Mesh</a> : <span class="keyword">public</span> <a class="code" href="classRF22Router.html" title="RF22 subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a netw...">RF22Router</a>
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099 <span class="keyword">public</span>:
<a name="l00100"></a>00100 <span class="comment"></span>
<a name="l00101"></a>00101 <span class="comment">    /// The maximum length permitted for the application payload data in a RF22Mesh message</span>
<a name="l00102"></a>00102 <span class="comment"></span><span class="preprocessor">    #define RF22_MESH_MAX_MESSAGE_LEN (RF22_ROUTER_MAX_MESSAGE_LEN - sizeof(RF22Mesh::MeshMessageHeader))</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00104"></a>00104 <span class="comment">    /// Structure of the basic RF22Mesh header.</span>
<a name="l00105"></a><a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html">00105</a> <span class="comment"></span>    <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00106"></a>00106     {
<a name="l00107"></a><a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html#a0f6a9f473ad7cd1d4b15ba305d9a425f">00107</a>         uint8_t             <a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html#a0f6a9f473ad7cd1d4b15ba305d9a425f" title="Type of RF22Mesh message, one of RF22_MESH_MESSAGE_TYPE_*.">msgType</a>;  <span class="comment">///&lt; Type of RF22Mesh message, one of RF22_MESH_MESSAGE_TYPE_*</span>
<a name="l00108"></a>00108 <span class="comment"></span>    } <a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html" title="Structure of the basic RF22Mesh header.">MeshMessageHeader</a>;
<a name="l00109"></a>00109 <span class="comment"></span>
<a name="l00110"></a>00110 <span class="comment">    /// Signals an application layer message for the caller of RF22Mesh</span>
<a name="l00111"></a><a class="code" href="structRF22Mesh_1_1MeshApplicationMessage.html">00111</a> <span class="comment"></span>    <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00112"></a>00112     {
<a name="l00113"></a><a class="code" href="structRF22Mesh_1_1MeshApplicationMessage.html#a2e680c0521baba53b1f84972b35e0363">00113</a>         <a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html" title="Structure of the basic RF22Mesh header.">MeshMessageHeader</a>   <a class="code" href="structRF22Mesh_1_1MeshApplicationMessage.html#a2e680c0521baba53b1f84972b35e0363" title="msgType = RF22_MESH_MESSAGE_TYPE_APPLICATION">header</a>; <span class="comment">///&lt; msgType = RF22_MESH_MESSAGE_TYPE_APPLICATION </span>
<a name="l00114"></a><a class="code" href="structRF22Mesh_1_1MeshApplicationMessage.html#a1171396bb32a05a08cbabfb4cd4e69f5">00114</a> <span class="comment"></span>        uint8_t             data[RF22_MESH_MAX_MESSAGE_LEN]; <span class="comment">///&lt; Applicaiotn layer payload data</span>
<a name="l00115"></a>00115 <span class="comment"></span>    } <a class="code" href="structRF22Mesh_1_1MeshApplicationMessage.html" title="Signals an application layer message for the caller of RF22Mesh.">MeshApplicationMessage</a>;
<a name="l00116"></a>00116 <span class="comment"></span>
<a name="l00117"></a>00117 <span class="comment">    /// Signals a route discovery request or reply</span>
<a name="l00118"></a>00118 <span class="comment">    /// At present only supports physical dest addresses of length 1 octet</span>
<a name="l00119"></a><a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html">00119</a> <span class="comment"></span>    <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00120"></a>00120     {
<a name="l00121"></a><a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#afed272ef1016b03e354289f34abe513e">00121</a>         <a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html" title="Structure of the basic RF22Mesh header.">MeshMessageHeader</a>   <a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#afed272ef1016b03e354289f34abe513e" title="msgType = RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_*">header</a>; <span class="comment">///&lt; msgType = RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_*</span>
<a name="l00122"></a><a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#ad89cd92174435ef6ef46dd203d772b25">00122</a> <span class="comment"></span>        uint8_t             <a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#ad89cd92174435ef6ef46dd203d772b25" title="Reserved. Must be 1.">destlen</a>; <span class="comment">///&lt; Reserved. Must be 1.</span>
<a name="l00123"></a><a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#a2cf61d5f945312e01250492699485de9">00123</a> <span class="comment"></span>        uint8_t             <a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#a2cf61d5f945312e01250492699485de9" title="The address of the destination node whose route is being sought.">dest</a>;   <span class="comment">///&lt; The address of the destination node whose route is being sought</span>
<a name="l00124"></a><a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html#a74746e84ecee3c98f59a3e747b4ac663">00124</a> <span class="comment"></span>        uint8_t             <a class="code" href="classRF22Mesh.html#ae7a3ab2784aaf45ab2d47e5d9ce5b405">route</a>[RF22_MESH_MAX_MESSAGE_LEN - 1]; <span class="comment">///&lt; List of node addresses visited so far. Length is implcit</span>
<a name="l00125"></a>00125 <span class="comment"></span>    } <a class="code" href="structRF22Mesh_1_1MeshRouteDiscoveryMessage.html">MeshRouteDiscoveryMessage</a>;
<a name="l00126"></a>00126 <span class="comment"></span>
<a name="l00127"></a>00127 <span class="comment">    /// Signals a route failure</span>
<a name="l00128"></a><a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html">00128</a> <span class="comment"></span>    <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00129"></a>00129     {
<a name="l00130"></a><a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html#a7a52ddf10f1f6e0921c46c192a0d41ec">00130</a>         <a class="code" href="structRF22Mesh_1_1MeshMessageHeader.html" title="Structure of the basic RF22Mesh header.">MeshMessageHeader</a>   <a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html#a7a52ddf10f1f6e0921c46c192a0d41ec" title="msgType = RF22_MESH_MESSAGE_TYPE_ROUTE_FAILURE">header</a>; <span class="comment">///&lt; msgType = RF22_MESH_MESSAGE_TYPE_ROUTE_FAILURE</span>
<a name="l00131"></a><a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html#ac09822c23ede1efa41ef98ae239984e0">00131</a> <span class="comment"></span>        uint8_t             <a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html#ac09822c23ede1efa41ef98ae239984e0" title="The address of the destination towards which the route failed.">dest</a>; <span class="comment">///&lt; The address of the destination towards which the route failed</span>
<a name="l00132"></a>00132 <span class="comment"></span>    } <a class="code" href="structRF22Mesh_1_1MeshRouteFailureMessage.html" title="Signals a route failure.">MeshRouteFailureMessage</a>;
<a name="l00133"></a>00133 <span class="comment"></span>
<a name="l00134"></a>00134 <span class="comment">    /// Constructor. </span>
<a name="l00135"></a>00135 <span class="comment">    /// \param[in] thisAddress The address to assign to this node. Defaults to 0</span>
<a name="l00136"></a>00136 <span class="comment">    /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before</span>
<a name="l00137"></a>00137 <span class="comment">    /// accessing it</span>
<a name="l00138"></a>00138 <span class="comment">    /// \param[in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)</span>
<a name="l00139"></a>00139 <span class="comment"></span>    <a class="code" href="classRF22Mesh.html#acfabd46c192bd547460b9b86e0f68607">RF22Mesh</a>(uint8_t thisAddress = 0, uint8_t slaveSelectPin = 10, uint8_t interrupt = 0);
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment">    /// Sends a message to the destination node. Initialises the RF22Router message header </span>
<a name="l00142"></a>00142 <span class="comment">    /// (the SOURCE address is set to the address of this node, HOPS to 0) and calls </span>
<a name="l00143"></a>00143 <span class="comment">    /// route() which looks up in the routing table the next hop to deliver to.</span>
<a name="l00144"></a>00144 <span class="comment">    /// If no route is known, initiates route discovery and waits for a reply.</span>
<a name="l00145"></a>00145 <span class="comment">    /// Then sends the message to the next hop</span>
<a name="l00146"></a>00146 <span class="comment">    /// Then waits for an acknowledgement from the next hop </span>
<a name="l00147"></a>00147 <span class="comment">    /// (but not from the destination node (if that is different).</span>
<a name="l00148"></a>00148 <span class="comment">    /// \param [in] buf The application message data</span>
<a name="l00149"></a>00149 <span class="comment">    /// \param [in] len Number of octets in the application message data. 0 is permitted</span>
<a name="l00150"></a>00150 <span class="comment">    /// \param [in] dest The destination node address</span>
<a name="l00151"></a>00151 <span class="comment">    /// \return The result code:</span>
<a name="l00152"></a>00152 <span class="comment">    ///         - RF22_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop </span>
<a name="l00153"></a>00153 <span class="comment">    ///           (not necessarily to the final dest address)</span>
<a name="l00154"></a>00154 <span class="comment">    ///         - RF22_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table</span>
<a name="l00155"></a>00155 <span class="comment">    ///         - RF22_ROUTER_ERROR_UNABLE_TO_DELIVER Noyt able to deliver to the next hop </span>
<a name="l00156"></a>00156 <span class="comment">    ///           (usually because it dod not acknowledge due to being off the air or out of range</span>
<a name="l00157"></a>00157 <span class="comment"></span>    uint8_t <a class="code" href="classRF22Mesh.html#ada9dcba842569c7f126fdb1d085753a5">sendtoWait</a>(uint8_t* buf, uint8_t len, uint8_t dest);
<a name="l00158"></a>00158 <span class="comment"></span>
<a name="l00159"></a>00159 <span class="comment">    /// Starts the receiver if it is not running already.</span>
<a name="l00160"></a>00160 <span class="comment">    /// If there is a valid application layer message available for this node (or RF22_BROADCAST_ADDRESS), </span>
<a name="l00161"></a>00161 <span class="comment">    /// send an acknowledgement to the last hop</span>
<a name="l00162"></a>00162 <span class="comment">    /// address (blocking until this is complete), then copy the application message payload data</span>
<a name="l00163"></a>00163 <span class="comment">    /// to buf and return true</span>
<a name="l00164"></a>00164 <span class="comment">    /// else return false. </span>
<a name="l00165"></a>00165 <span class="comment">    /// If a message is copied, *len is set to the length..</span>
<a name="l00166"></a>00166 <span class="comment">    /// If from is not NULL, the originator SOURCE address is placed in *source.</span>
<a name="l00167"></a>00167 <span class="comment">    /// If to is not NULL, the DEST address is placed in *dest. This might be this nodes address or </span>
<a name="l00168"></a>00168 <span class="comment">    /// RF22_BROADCAST_ADDRESS. </span>
<a name="l00169"></a>00169 <span class="comment">    /// This is the preferred function for getting messages addressed to this node.</span>
<a name="l00170"></a>00170 <span class="comment">    /// If the message is not a broadcast, acknowledge to the sender before returning.</span>
<a name="l00171"></a>00171 <span class="comment">    /// \param[in] buf Location to copy the received message</span>
<a name="l00172"></a>00172 <span class="comment">    /// \param[in,out] len Available space in buf. Set to the actual number of octets copied.</span>
<a name="l00173"></a>00173 <span class="comment">    /// \param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address</span>
<a name="l00174"></a>00174 <span class="comment">    /// \param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address</span>
<a name="l00175"></a>00175 <span class="comment">    /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID</span>
<a name="l00176"></a>00176 <span class="comment">    /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS</span>
<a name="l00177"></a>00177 <span class="comment">    /// (not just those addressed to this node).</span>
<a name="l00178"></a>00178 <span class="comment">    /// \return true if a valid message was recvived for this node and copied to buf</span>
<a name="l00179"></a>00179 <span class="comment"></span>    <span class="keywordtype">boolean</span> <a class="code" href="classRF22Mesh.html#a5702996188d7b3941a844fc4d39a6f57">recvfromAck</a>(uint8_t* buf, uint8_t* len, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* <span class="keywordtype">id</span> = NULL, uint8_t* flags = NULL);
<a name="l00180"></a>00180 <span class="comment"></span>
<a name="l00181"></a>00181 <span class="comment">    /// Starts the receiver if it is not running already.</span>
<a name="l00182"></a>00182 <span class="comment">    /// Similar to recvfromAck(), this will block until either a valid application layer </span>
<a name="l00183"></a>00183 <span class="comment">    /// message available for this node</span>
<a name="l00184"></a>00184 <span class="comment">    /// or the timeout expires. </span>
<a name="l00185"></a>00185 <span class="comment">    /// \param[in] buf Location to copy the received message</span>
<a name="l00186"></a>00186 <span class="comment">    /// \param[in,out] len Available space in buf. Set to the actual number of octets copied.</span>
<a name="l00187"></a>00187 <span class="comment">    /// \param[in] timeout Maximum time to wait in milliseconds</span>
<a name="l00188"></a>00188 <span class="comment">    /// \param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address</span>
<a name="l00189"></a>00189 <span class="comment">    /// \param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address</span>
<a name="l00190"></a>00190 <span class="comment">    /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID</span>
<a name="l00191"></a>00191 <span class="comment">    /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS</span>
<a name="l00192"></a>00192 <span class="comment">    /// (not just those addressed to this node).</span>
<a name="l00193"></a>00193 <span class="comment">    /// \return true if a valid message was copied to buf</span>
<a name="l00194"></a>00194 <span class="comment"></span>    <span class="keywordtype">boolean</span> <a class="code" href="classRF22Mesh.html#a09ff3e2f1481180881ead85c069fe547">recvfromAckTimeout</a>(uint8_t* buf, uint8_t* len,  uint16_t timeout, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* <span class="keywordtype">id</span> = NULL, uint8_t* flags = NULL);
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 <span class="keyword">protected</span>:
<a name="l00197"></a>00197 <span class="comment"></span>
<a name="l00198"></a>00198 <span class="comment">    /// Internal function that inspects messages being received and adjusts the routing table if necessary.</span>
<a name="l00199"></a>00199 <span class="comment">    /// Called by recvfromAck() immediately after it gets the message from RF22ReliableDatagram</span>
<a name="l00200"></a>00200 <span class="comment">    /// \param [in] message Pointer to the RF22Router message that was received.</span>
<a name="l00201"></a>00201 <span class="comment">    /// \param [in] messageLen Length of message in octets</span>
<a name="l00202"></a>00202 <span class="comment"></span>    <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRF22Mesh.html#a340dba041b6d8e83a6ce6a4f613eb112">peekAtMessage</a>(<a class="code" href="structRF22Router_1_1RoutedMessage.html" title="Defines the structure of a RF22Router message.">RoutedMessage</a>* message, uint8_t messageLen);
<a name="l00203"></a>00203 <span class="comment"></span>
<a name="l00204"></a>00204 <span class="comment">    /// Internal function that inspects messages being received and adjusts the routing table if necessary.</span>
<a name="l00205"></a>00205 <span class="comment">    /// This is virtual, which lets subclasses override or intercept the route() function.</span>
<a name="l00206"></a>00206 <span class="comment">    /// Called by sendtoWait after the message header has been filled in.</span>
<a name="l00207"></a>00207 <span class="comment">    /// \param [in] message Pointer to the RF22Router message to be sent.</span>
<a name="l00208"></a>00208 <span class="comment">    /// \param [in] messageLen Length of message in octets</span>
<a name="l00209"></a>00209 <span class="comment"></span>    <span class="keyword">virtual</span> uint8_t <a class="code" href="classRF22Mesh.html#ae7a3ab2784aaf45ab2d47e5d9ce5b405">route</a>(<a class="code" href="structRF22Router_1_1RoutedMessage.html" title="Defines the structure of a RF22Router message.">RoutedMessage</a>* message, uint8_t messageLen);
<a name="l00210"></a>00210 <span class="comment"></span>
<a name="l00211"></a>00211 <span class="comment">    /// Try to resolve a route for the given address. Blocks while discovering the route</span>
<a name="l00212"></a>00212 <span class="comment">    /// which may take up to 4000 msec.</span>
<a name="l00213"></a>00213 <span class="comment">    /// Virtual so subclasses can override.</span>
<a name="l00214"></a>00214 <span class="comment">    /// \param [in] address The physical addres to resolve</span>
<a name="l00215"></a>00215 <span class="comment">    /// \return true if the address was resolved and added to the local routing table</span>
<a name="l00216"></a>00216 <span class="comment"></span>    <span class="keyword">virtual</span> <span class="keywordtype">boolean</span> <a class="code" href="classRF22Mesh.html#a276fbdde9038cb38e3ba2d6cffa95a4c">doArp</a>(uint8_t address);
<a name="l00217"></a>00217 <span class="comment"></span>
<a name="l00218"></a>00218 <span class="comment">    /// Tests if the given address of length addresslen is indentical to the</span>
<a name="l00219"></a>00219 <span class="comment">    /// physical addres of this node.</span>
<a name="l00220"></a>00220 <span class="comment">    /// RF22Mesh always ikmplements p[hysical addresses as the 1 octet address of the node</span>
<a name="l00221"></a>00221 <span class="comment">    /// given by _thisAddress</span>
<a name="l00222"></a>00222 <span class="comment">    /// Called by recvfromAck() to test whether a RF22_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST</span>
<a name="l00223"></a>00223 <span class="comment">    /// is for this node.</span>
<a name="l00224"></a>00224 <span class="comment">    /// Subclasses may want to override to implemnt mode complicated or longer physical addresses</span>
<a name="l00225"></a>00225 <span class="comment">    /// \param [in] address Address of the pyysical addres being tested</span>
<a name="l00226"></a>00226 <span class="comment">    /// \param [in] addresslen Lengthof the address in bytes</span>
<a name="l00227"></a>00227 <span class="comment">    /// \return true if the physical address of this node is identical to address</span>
<a name="l00228"></a>00228 <span class="comment"></span>    <span class="keyword">virtual</span> <span class="keywordtype">boolean</span> <a class="code" href="classRF22Mesh.html#aa619f98b3156358bcb0258ab1f50f46d">isPhysicalAddress</a>(uint8_t* address, uint8_t addresslen);
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 <span class="keyword">private</span>:<span class="comment"></span>
<a name="l00231"></a>00231 <span class="comment">    /// Temporary mesage buffer</span>
<a name="l00232"></a>00232 <span class="comment"></span>    <span class="keyword">static</span> uint8_t _tmpMessage[RF22_ROUTER_MAX_MESSAGE_LEN];
<a name="l00233"></a>00233 
<a name="l00234"></a>00234 };
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 <span class="preprocessor">#endif</span>
<a name="l00237"></a>00237 <span class="preprocessor"></span>
</pre></div></div>
</div>


<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
